/*
 * @(#)jTunes.java
 * 
 * Copyright(C) 2004 Yujin Kim
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.netexplode.jtunes.client.player;

import javax.swing.JFrame;

import com.netexplode.jtunes.client.ui.component.MainPanel;
import com.netexplode.jtunes.model.media.CollectionManager;
import com.netexplode.jtunes.model.media.Tag;

/**
 * <code>jTunes</code> represents .....
 * 
 * @author ykim
 * @version $Revision: 1.8 $
 * @since 0.1
 */
public class jTunes {

    // private static final Log log = LogFactory.getLog(jTunes.class);

    private static MainPanel main;

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {
        new Initializer();
        main = new MainPanel();
        // Schedule a job for the event-dispatching thread:
        // creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }

    private static void createAndShowGUI() {
        // Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);

        // Create and set up the window.
        JFrame frame = new JFrame("jTunes");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(main);
        // frame.setSize(640, 480);
        frame.setResizable(true);

        // Display the window.
        frame.pack();
        frame.setVisible(true);
    }

    public synchronized static void refreshLibraryPanel() {
        main.refreshLibraryPanel();
    }

    public synchronized static void refreshTree() {
        main.refreshTree();
    }

    public static void refreshSharedCollectionPanel() {
        new Thread() {
            public void run() {
                main.refreshSharedCollectionPanel();
                refreshLibraryPanel();
                refreshTree();
            }
        }.start();
        // main.refreshSharedCollectionPanel();
        // refreshLibraryPanel();
        // refreshTree();
    }

    public synchronized static void setAlbumArtPanelVisible(boolean visible) {
        main.setAlbumArtPanelVisible(visible);
    }

    public synchronized static void setLcdPanelText() {
        // @todo update displayable tag string
        final Tag tag = CollectionManager
                .getInstance()
                .getCurrentMediaFile()
                .getTag();
        main.setLcdPanelText(tag.getTitle() + "\n" + " - \n" + tag.getArtist());
    }
}